<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../../vue.js"></script>
</head>

<body>

  <div id="app">
    <input type="text" ref="myinput">
    <compa></compa>
  </div>


  <script>

    // Vue.component


    const compb = {
      template: '<h2>compb-{{$root.username}}-{{$parent.title}}</h2>',
      data() {
        return {
          title: 'from compb title'
        }
      },
      mounted() {
        console.log(this.$root.username)
        console.log(this.$parent.title)
        console.log(this.$parent.start())
      }
    }


    const compa = {
      props: ['user'],
      template: `
      <div>
        <h1>
          gp18-compa
        </h1>
        <compb ref="refCompb" ></compb>
      </div>
      `,
      data() {
        return {
          title: "from compa title"
        }
      },
      methods: {
        start() {
          console.log('compa start ...')
        }
      },
      components: {
        compb
      },
      mounted() {
        console.log(this.$refs.refCompb.title);
      }
    }


    var vm = new Vue({
      el: "#app",
      data: {
        username: 'hanye'
      },
      components: {
        compa
      },
      mounted() {
        console.log(this.$refs.myinput);
      }
    })

  </script>

</body>

</html>